﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Database;
public partial class admin_SuaCT_DDHLK : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var pm = new checkLogin();
        pm.redirectToLoginPage(); 
        if (!IsPostBack)
            {
                if (Session["tenkh"] == "Admin")
                {
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    ddlmalinhkien.DataSource = LinhKien.DSLK().Tables[0];
                    ddlmalinhkien.DataTextField = "tenlinhkien";
                    ddlmalinhkien.DataValueField = "malinhkien";
                    ddlmalinhkien.DataBind();

                    LayThongTin();
                }
            }
        }
        public void LayThongTin()
        {
            int maddh = int.Parse(Request.QueryString["maddh"].ToString());
            CT_DonDatHangLK ctddhlk = new CT_DonDatHangLK();
            ctddhlk = ctddhlk.ThongTinCTDDHLK(maddh);
            this.txtMaDDH.Text = ctddhlk.Maddh.ToString();
            this.txtSoLuong.Text = ctddhlk.SoLuong.ToString();
            this.txtGiaBan.Text = ctddhlk.GiaBan.ToString();
            this.ddlmalinhkien.SelectedValue = ctddhlk.MaLinhKien.ToString();

        }
        protected void btSave_Click(object sender, EventArgs e)
        {
            int maddh = int.Parse(txtMaDDH.Text);
            int malinhkien = int.Parse(ddlmalinhkien.SelectedValue.ToString());
            int soluong = int.Parse(txtSoLuong.Text);
            float giaban = float.Parse(txtGiaBan.Text);
            CT_DonDatHangLK ctddhlk = new CT_DonDatHangLK();
            ctddhlk.CapNhatCTDDHLK(maddh, malinhkien, soluong, giaban);
            Response.Redirect("HienthiCT_DDHLK.aspx");
        }

        protected void btCancel_Click(object sender, EventArgs e)
        {
            this.txtSoLuong.Text = "";
            this.txtGiaBan.Text = "";
        }
    }
    

